<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 求出1-1/2+1/3-1/4…..1/100的和 var i=1; -->
    <script>
        var i = 1
        var a = 0
        var b = 0
        var add = 0
        var reduce = 0

        while (i <= 100) {
            if (i % 2 == 0) {
                a = (i + 1)
                add += a
                console.log(add)
            }
            else {
                b = (i - 1)
                reduce += b
            }
            i++
        }
        var res = add + reduce
        console.log(res)

    </script>
</body>

</html>